package com.ccmusic.filter;

import java.io.IOException;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.annotation.WebFilter;
/**
 * 字符编码过滤器，统一设置UTF-8
 * @Author Phantom Assassin
 * @Date 2019年3月28日 下午9:50:11
 */
@WebFilter(value = { "*.do","/CCMusicSys/personal.jsp","/CCMusicSys/homePage.jsp"})
public class EncodingFilter implements Filter {

	@Override
	public void destroy() {

	}

	@Override
	public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
			throws IOException, ServletException {
		request.setCharacterEncoding("utf-8");
		response.setCharacterEncoding("utf-8");
		//控制台输出看是否过滤了
		//System.out.println("EncodingFilter 过滤了！");
		chain.doFilter(request, response);

	}

	@Override
	public void init(FilterConfig arg0) throws ServletException {

	}

}
